package com.jm.bishe.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.google.code.kaptcha.Constants;
import com.jm.bishe.entity.LoginBody;
import com.jm.bishe.entity.Result;
import com.jm.bishe.entity.RoomAdd;
import com.jm.bishe.entity.SuperAdmin;
import com.jm.bishe.service.Impl.RoomServiceImpl;
import com.jm.bishe.service.Impl.SuperAdminServiceImpl;
import com.jm.bishe.service.SuperAdminService;
import com.jm.bishe.utils.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.sql.rowset.serial.SerialBlob;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.Blob;
import java.sql.SQLException;

@RestController
@RequestMapping("/sys/super")
public class SuperAdminController {


    @Autowired
    private RoomServiceImpl roomService;

    @Autowired
    private SuperAdminServiceImpl superAdminService;

    @PostMapping("/login")
    @ResponseBody
    public Result login(@RequestBody LoginBody loginBody, HttpServletRequest request) {
        String checkCode = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        if (loginBody.getCode() != null && !loginBody.getCode().equals("")) {
            if (checkCode.equals(loginBody.getCode())) {
                return superAdminService.login(loginBody.getPhoneNumber(), loginBody.getPassWord());
            }
            return Result.falure(2002, "验证码错误", null);
        }
        return Result.falure(2002, "请输入验证码", null);
    }


}
